//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Policy Injection Application Block
//===============================================================================

using System;
using System.Windows.Forms;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace EntLibContrib.PolicyInjection.CallHandlers
{
	/// <summary>
	/// An attribute used to apply the <see cref="CursorCallHandler"/> to the target.
	/// </summary>
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Method)]
	public sealed class CursorCallHandlerAttribute : HandlerAttribute
	{
		#region Fields
		private string name;
		private static CursorConverter converter = new CursorConverter();
		#endregion

		#region Properties
		/// <summary>
		/// Gets the cursor name.
		/// </summary>
		/// <value>cursor name.</value>
		public string Name
		{
			get { return name; }
		}

		/// <summary>
		/// Gets the cursor.
		/// </summary>
		/// <value>The cursor.</value>
		public Cursor Cursor
		{
			get { return (Cursor)converter.ConvertFromString(Name); }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Creates a new <see cref="CursorCallHandlerAttribute"/>.
		/// </summary>
		public CursorCallHandlerAttribute()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="CursorCallHandlerAttribute"/> class.
		/// </summary>
		/// <param name="name">The cursor name.</param>
		public CursorCallHandlerAttribute(string name)
		{
			this.name = name;
		}
		#endregion

		#region Public Fields
		/// <summary>
		/// Derived classes implement this method. When called, it
		/// creates a new call handler as specified in the attribute
		/// configuration.
		/// </summary>
		/// <param name="container">The <see cref="T:Microsoft.Practices.Unity.IUnityContainer"/> to use when creating handlers,
		/// if necessary.</param>
		/// <returns>A new call handler object.</returns>
		public override ICallHandler CreateHandler(IUnityContainer container)
		{
			return new CursorCallHandler(Cursor, Order);
		}
		#endregion
	}
}
